<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>亿信聊天室 首页</title>
    <link rel="stylesheet" href="css/style.css">
    <link rel="stylesheet" href="css/public.css">
    <link rel="stylesheet" href="css/swiper-3.4.2.min.css">
    <script src="js/jquery-1.10.1.min.js"></script>
    <script src="js/swiper-3.4.2.jquery.min.js"></script>
    <script src="//cdn.bootcss.com/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
</head>
<body>
<header>
    <div class="top">
        <div class="container">
            <!--未登录状态-->
            <div class="login">
                <div class="top-reg">
                    <div class="denglu fl">
                        <a href="reg/login.html"><span><img src="images/icon_wdzh.png" alt="">登陆</span></a>
                    </div>
                    <div class="fl line"></div>
                    <div class="zhuce fl">
                        <a href="reg/reg.html"><span><img src="images/icon_yhgl.png" alt="">注册</span></a>
                    </div>
                    <div class="clearfix"></div>
                </div>
                <div class="top-tips">
                    <span>游客，您好！</span>
                    您是第666位访问网站的人
                </div>
            </div>
            <!-- 登陆状态 -->
            <div class="login success" style="display: none">
                <div class="top-reg">
                    <div class="qiandao fl">
                        <a href="javascript:;" class="qd"><span><img src="images/icon_rl.png" alt="">签到</span></a>
                    </div>
                    <div class="fl line"></div>
                    <div class="tongzhi fl">
                        <a href="menber/message.html"><span><img src="images/icon_tz.png" alt="">通知</span></a>
                    </div>
                    <div class="fl line"></div>
                    <div class="tongzhi fl">
                        <a href="menber/menber.html"><span><img src="images/icon_grzx.png" alt="">个人中心</span></a>
                    </div>
                    <div class="fl line"></div>
                    <div class="tongzhi fl">
                        <a href="javascript:;" class="loginout"><span><img src="images/icon_aqtc.png" alt="">安全退出</span></a>
                    </div>
                    <div class="clearfix"></div>
                </div>
                <div class="top-tips">
                    <span class="top_username">xxx</span>，您好！
                    当前在线人数666人
                </div>
            </div>
        </div>
    </div>
    <div class="logo">
        <div class="container">
            <div class="logoimg fl">
                <a href="index.html"><img src="images/icon_logo.png" alt=""></a>
            </div>
            <div class="logoright fr">
                <li class="on"><a href="index.html">首页</a></li>
                <li><a href="javascript:;" class="addroom">创建房间</a></li>
                <li><a href="javascript:;"><img src="images/icon_nav.png" alt=""></a></li>
                <div class="search-box fl">
                    <input type="text" class="search" placeholder="请输入房间ID">
                    <img src="images/icon_search.png" alt="">
                    <div class="result_box">

                    </div>
                </div>
            </div>
        </div>
    </div>
</header>
<!--banner-->
<div class="banner">
    <div class="swiper-container">
        <div class="swiper-wrapper">
            <div class="swiper-slide">
                <img src="images/banner.png" alt="">
            </div>
            <div class="swiper-slide">
                <img src="images/banner.png" alt="">
            </div>
            <div class="swiper-slide">
                <img src="images/banner.png" alt="">
            </div>
        </div>
        <div class="swiper-pagination"></div>
    </div>
</div>
<!-- banner end -->

<div class="show-list">
    <div class="show-title">
        <span class="en">HOT CHAT ROOM</span>
        <h4>热门聊天室</h4>
        <div class="line"></div>
    </div>
    <div class="show-listbox">
        <ul class="container">
            <!--<div style="text-align: center;font-size: 20px;margin: 20px auto;">正在加载···</div>-->
            <!--<div class="clearfix"></div>-->
        </ul>
        <div class="loading">
            <span class="line fl"></span>
            <div class="more fl">
                <a href="javascript:;" class="room_more">加载更多</a>
            </div>
            <span class="line fl"></span>
            <div class="clearfix"></div>
        </div>
    </div>
</div>
<!--footer-->
<footer>
    <div class="container">
        <div class="footer-list">
            <div class="footer-tit">
                联系我们
            </div>
            <ul>
                <li><a href="tencent://message/?uin=88888888&Site=&menu=yes">商务QQ:11111111</a></li>
                <li>技术咨询:11111111</li>
                <li>联系电话:11111111</li>
            </ul>
        </div>
        <div class="footer-list">
            <div class="footer-tit">
                常见问题
            </div>
            <ul>
                <li><a href="javascript:;">账号问题</a></li>
                <li><a href="javascript:;">常见问题</a></li>
                <li><a href="javascript:;">新手入门</a></li>
            </ul>
        </div>
        <div class="footer-list">
            <div class="footer-tit">
                关于我们
            </div>
            <ul>
                <li><a href="javascript:;">公司介绍</a></li>
                <li><a href="javascript:;">隐私政策</a></li>
                <li><a href="javascript:;">免责声明</a></li>
            </ul>
        </div>
        <div class="footer-list">
            <div class="footer-tit">
                友情链接
            </div>
            <ul>
                <li><a href="javascript:;">xxxx网</a></li>
                <li><a href="javascript:;">xxxx网</a></li>
                <li><a href="javascript:;">xxxx网</a></li>
            </ul>
        </div>
        <div class="footer-list">
            <img src="images/icon_logo1.png" alt="">
        </div>
        <div class="clearfix"></div>
    </div>    
</footer>
<div class="copyright">
    <div class="container">
        <div class="fr">川ICP备案号xxxxx号</div>
        <div class="cpr">Copyright ©聊天室网 2014-2018.All rights reseved</div>
    </div>
</div>


<div class="warning pwd">
    <div class="room_password">
        <input type="text" placeholder="请输入直播间密码">
        <a href="javascript:;">确定</a>
    </div>
</div>


<!--fooer end-->

<script>
    $(window).ready(function(){
        var page = 1;
        var maxpage='';
        function  room_list(s){
            $.ajax({
                url:'http://shishi2017.com/api//home/get_chatroom_info',
                type:'POST',
                datatype:'json',
                data:{uid:$.cookie('user_id'),token:$.cookie('user_token'),key_words:'',chat_id:'',search_uid:'',page:s},
                success:(function (chats) {
                    var room = JSON.parse(chats);
                    maxpage = room.data.total_page;
                    var s = room.data.back_data;
                    var text='';
                    for(num in s){
                        text+=
                            '<li>'+
                            '<a href="javascript:;"  class="go_room" data-pwd="'+s[num].room_password+'" data-number="'+s[num].id+'" style="background: url('+s[num].back_url+') center center;background-size: cover">'+
                            '<div class="sp-info">'+
                            '<span class="hot">'+
                            '<img src="images/icon_hot.png" alt="">'+
                            '热度：'+s[num].hot+
                            '</span>'+
                            '<span class="keywords">'+
                            '关键词：'+s[num].key_words+
                            '</span>'+
                            '</div>'+
                            '</a>'+
                            '</li>'
                    };
                    $('.show-listbox .container').append(text);
                }),
                error:(function(es){
                    console.log(es);
                })
            });
        }
        room_list(page);
        $('a.room_more').click(function(){
            if(page<maxpage){
                page++;
            }else{
                $('a.room_more').html('已经加载全部了！');
                $('.loading').width('400px');
                return false;
            }
            room_list(page);
        });
        $(document).on('click','.go_room' ,function(){
            if($(this).data('pwd')!=''&& typeof $(this).data('pwd')!='undefined'){
                $('.warning.pwd').show();
                var pwd = $(this).data('pwd');
                var oldroomid = roomid;
                var roomid = $(this).data('number');
                $.cookie('old_room_id',oldroomid,{path:'/'});
                $.cookie('room_id',roomid,{path:'/'});
                $('.room_password a').click(function(){
                   if($('.room_password input').val()!=pwd){
                       alert('密码错误，无法进入');
                       return false;
                   }else{
                       $(window).attr('location','chatroom.html');
                   }
                });
            }else{
                var roomid = $(this).data('number');
                var oldroomid = $.cookie('room_id');
                $.cookie('old_room_id',oldroomid,{path:'/'});
                $.cookie('room_id',roomid,{path:'/'});
                $(window).attr('location','chatroom.html')
            }
        });

    });
</script>

<script>
    var mySwiper = new Swiper ('.swiper-container', {
        pagination : '.swiper-pagination',
        autoplay : 3000,
    });
    $(document).on('click','.result-btn',function(){
        $.cookie('old_room_id',$.cookie('room_id'),{path:'/'});
        $.cookie('room_id',$(this).data('roomid'),{path:'/'});
        $(window).attr('location','chatroom.html');
    });

    //签到窗口
    (function(){
        var qd_time = new Date();
        var qd_year =qd_time.getFullYear();
        var qd_month =qd_time.getMonth()+1<10? '0'+(qd_time.getMonth()+1):(qd_time.getMonth()+1);
        var qd_d =qd_time.getDate();
        var qd_day = qd_time.getDate()<10?'0'+qd_time.getDate():qd_time.getDate();
        var qd_days;
        $.ajax({
            url:'http://shishi2017.com/api/home/sign_famous',
            type:'POST',
            datatype:'json',
            data:{
                uid:$.cookie('user_id'),
                token:$.cookie('user_token')
            },success:(function(ea){
                ea = JSON.parse(ea);
                console.log(ea);
                if(ea.ret==200){
                    days = ea.data.data;
                    function GetDateStr(AddDayCount) {
                        var dd = new Date();
                        dd.setDate(dd.getDate()+AddDayCount);//获取AddDayCount天后的日期
                        var y = dd.getFullYear();
                        var m = dd.getMonth()+1<10?'0'+(dd.getMonth()+1):dd.getMonth()+1;
                        var d = dd.getDate()<10?'0'+dd.getDate():dd.getDate();
                        return y+"-"+m+"-"+d;
                    }
                    daylist =  "<li data-qd='"+GetDateStr(-3)+"'>"+ GetDateStr(-3).substring(8,10) +"</li>" +
                        "<li data-qd='"+GetDateStr(-2)+"'>"+GetDateStr(-2).substring(8,10)+"</li>" +
                        "<li data-qd='"+GetDateStr(-1)+"'>"+GetDateStr(-1).substring(8,10)+"</li>" +
                        "<li data-qd='"+GetDateStr(0)+"'>"+GetDateStr(0).substring(8,10)+"</li>" +
                        "<li data-qd='"+GetDateStr(1)+"'>"+GetDateStr(1).substring(8,10)+"</li>" +
                        "<li data-qd='"+GetDateStr(2)+"'>"+GetDateStr(2).substring(8,10)+"</li>" +
                        "<li data-qd='"+GetDateStr(3)+"'>"+GetDateStr(3).substring(8,10)+"</li>";
                    var qdhtml='';
                    ea.data.is_sign ==0 ? qdhtml = '<div id=\'qiandao\' class="qiandao-success qdbtn">点击签到</div>' : qdhtml = '<div id=\'qiandao\' class="qiandao-success">已签到</div>';
                    $('.qd_days').html(ea.data.days);
                    var fixed =
                        "<div class=\"warning qiandao\">" +
                        "<div class=\"qiandaobox\">" +
                        "<a href=\"javascript:;\" class=\"qiandao-close\">" +
                        "<img src=\"images/icon_closed.png\" alt=\"\"></a>" +
                        "<div class=\"qiandaobg-box\"><div class=\"qiandao-month\">"+qd_month+"月</div>" +qdhtml +
                        "<div class=\"qiandao-num\">已连续签到 <span class='qd_days'>"+ea.data.days+"</span>天</div>" +
                        "</div><div class=\"qiandao-data-box\">" +
                        "<div class=\"qiandao-data-line-box\">" +
                        "<div class=\"qiandao-data-line\"></div>" +
                        "<div class=\"qiandao-data\">" +daylist+
                        "</div></div></div></div></div><div class=\"warning no_login\"><div class=\"warningbox\"><div class=\"waring-img\"><img src=\"images/img_tk_logo.png\" alt=\"\"></div><div class=\"warning-text\">您未获得权限，点击申请授权！</div><div class=\"warning-btn\"><a href=\"reg/reg.html\">申请授权</a></div></div></div>";
                    $('body').prepend(fixed);
                    for(num in days){
                        for(var i =num;i<7;i++){
                            days[num]==$('.qiandao-data li').eq(i).data('qd') ? $('.qiandao-data li').eq(i).addClass('on'): console.log() ;
                        }
                    }
                }else if(ea.ret==401){
                    alert('您已退出或已在其他设备登陆，请重新登陆')
                    $.cookie("user_token",null,{path:'/'});
                    $.cookie("user_head",null,{path:'/'});
                    $.cookie("user_id",null,{path:'/'});
                    $.cookie("user_nickname",null,{path:'/'});
                    $.cookie("user_r_token",null,{path:'/'});
                    $.cookie("user_sign",null,{path:'/'});
                    $.cookie("old_room_id",null,{path:'/'});
                    $.cookie("qdm",null,{path:'/'});
                    $.cookie("qtoken",null,{path:'/'});
                    $.cookie("room_id",null,{path:'/'});
                    $.cookie("user_sign",null,{path:'/'});
                    $.cookie("room_keyword",null,{path:'/'});
                    $.cookie("other_login",null,{path:'/'});
                    $(window).attr('location','reg/login.html');
                }else{

                }

            }),
        });
        $('body').on('click','.qdbtn',function(){
            $.ajax({
                url: 'http://shishi2017.com/api/home/sign_in',
                type: 'POST',
                datatype: 'json',
                data: {
                    uid:$.cookie('user_id'),
                    token:$.cookie('user_token')
                },success:(function(qd){
                    $('#qiandao').html('已签到');
                    $('#qiandao').removeClass('qdbtn');
                })
            });
        });
    })();
    (function(){
        $('.room_password').click(function (eventTag) {
            var event=eventTag||windows.event;
            var e=event.srcElement||event.target;
            event.stopPropagation?event.stopPropagation():window.event.cancelBubble = true;
        });
        $('.newroombox').click(function (eventTag) {
            var event=eventTag||windows.event;
            var e=event.srcElement||event.target;
            event.stopPropagation?event.stopPropagation():window.event.cancelBubble = true;
        });
        $(document).on('click','.qiandao-close',function () {
            $('.warning.qiandao').hide();
        });
        $('.success .qiandao').click(function () {
            $('.warning.qiandao').show();
        });
    })();

</script>

<script>
$('.top_username').html($.cookie('user_nickname'));
</script>
<script src="js/common.js"></script>
</body>
</html>